package com.probox.apiModules.controller.platfom;

import cn.hutool.core.util.ObjectUtil;
import com.probox.common.core.exception.BaseException;
import com.probox.common.core.utils.HttpUtil;
import com.probox.common.core.utils.SecurityUtils;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.entity.service.platfom.IPlatformSmsConfigService;
import com.probox.common.entity.service.wechat.IWechatAuthorizationInfoService;
import com.probox.wechat.api.domain.WechatAuthorizationInfoVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "平台设置模块", tags = {"短信信息接口"})
@RestController
@RequestMapping("/platform")
public class OpenPlatformSmsController extends BaseController {
    @Autowired
    private IPlatformSmsConfigService platformSmsConfigService;

    @Autowired
    private IWechatAuthorizationInfoService wechatAuthorizationInfoService;

    /**
     * 获取验证码
     *
     * @param phone
     * @param request
     * @return
     */
    @GetMapping(value = "/smsApi/phoneCode")
    public AjaxResult getPhoneCode(@RequestParam("phone") String phone, javax.servlet.http.HttpServletRequest request) {
        WechatAuthorizationInfoVo authorizationInfo = wechatAuthorizationInfoService.getAuthorizationInfo(SecurityUtils.getCustomerAppId());
        if (ObjectUtil.isEmpty(authorizationInfo)) throw new BaseException("没有绑定平台");
        if (ObjectUtil.isEmpty(phone)) throw new BaseException("手机号码不能为空！");
        platformSmsConfigService.smsLoginCodeAlibaba(phone, HttpUtil.getIp(request), Long.valueOf(authorizationInfo.getPlatformId()));
        return AjaxResult.success();
    }


}
